package prefuse.vensim;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

import prefuse.gui.InterfaceHandler;


public class CopyOfReadText {
	private BufferedReader br;
	private String line;
	private static HashMap<String,String> innerMap= new HashMap<String,String>();
	private static Map<String,HashMap<String,String>>  ValueMap = new HashMap<String,HashMap<String,String>>();
	private double value[] = new double[]{};
	public static HashMap<String,String> IHashMap;
	
	public  CopyOfReadText(InterfaceHandler interfaceHandler,String variableName) throws IOException{
		
	//	br = new BufferedReader(new FileReader(txtFilename));
		
		
		int OuterMapSize = 0;
		String OuterKey = "";
//		String[] columns = line.split("	");
		float[] timelist = interfaceHandler.gettimeVariable();
		float[] valuelist = interfaceHandler.getVariable();
		System.out.println("this is in class copyofreadtext: "+variableName);
		System.out.println("this is in class copyofreadtext "+timelist.length);
		System.out.println("this is in class copyofreadtext "+valuelist.length);
//		System.out.println("this is in class copyofreadtext"+innerMap.size());
		for(int i=0;i<timelist.length;i++){
			

			
			innerMap.put(String.valueOf(timelist[i]),String.valueOf(valuelist[i]));	
			System.out.println("innerMap.size() "+innerMap.size());
			ValueMap.put(variableName,innerMap);
			OuterKey = variableName;
			
			
		}

	
		
	}

	public void searchMap(String s,String[] time) throws IOException{	
	
		
		System.out.println("this isIHashMap: "+IHashMap);
		
		value = new double[]{};
		
		if(ValueMap.get(s)!=null){
			IHashMap = ValueMap.get(s);
			System.out.println("i am here s is : "+s);
			System.out.println("this isIHashMap after get in CopyOfReadText.java: "+IHashMap.size());
		}
		
		if ( time == null ){
			time = new String[]{""};
			}
		
		
		
		System.out.println("length of time aaaaaaaaaaaaaaaaaaaaaa.java "+time.length);
		
		for(int i=0; i<time.length; i++){
			
			System.out.println("length of value"+time[i]);
			
			System.out.println("if value is null?"+(value==null));
			System.out.println("if value 's length: "+ value.length);
			System.out.println("if value 's length: "+ (value.length==0));
			if(value==null){
				String tempAbc = IHashMap.get(time[i]);
				value[0] = Double.valueOf(tempAbc);
				
				System.out.println("bbbb" + value[0]);
			}
			else{
				System.out.println("this is time: " + time[i]);
				System.out.println("the length of value is : " + value.length);
				value=Arrays.copyOf(value, value.length+1);
		//		System.out.println("the value is : " + Double.valueOf(IHashMap.get(time[i])));
				value[value.length-1]=Double.valueOf(IHashMap.get(time[i]));
				
			}
		}
		
	}
	public double[] getValue(){
		return value;
	}
	public double getValue(String s,String time){
		HashMap<String,String> IHashMap = (HashMap) ValueMap.get(s);
		double temptime = Double.valueOf(time);
		double value = Double.valueOf(IHashMap.get(temptime));
		return value;
	}
	public static void main(String agrs[])
	 {  
//		try {
//			String[] t = new String[]{"0","1","2","3","4","5"};
//			CopyOfReadText a = new CopyOfReadText();
//			a.searchMap("NegativeOfCumulativeWNVSymptomaticCases",t);
//			double[] b = a.getValue();
//			
//			for(int i=0; i<b.length; i++){
//				System.out.println("the array value is : " + b[i]);
//			}
//
//		} catch (FileNotFoundException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		} catch (IOException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
	 }
}
